/*
 * FileComparisor.h
 *
 *  Created on: Aug 20, 2013
 *      Author: jeff
 */

#ifndef STREAMCOMPARISOR_H_
#define STREAMCOMPARISOR_H_

#include "Comparisor.h"

#include <fstream>
#include <iostream>

#define POST_FIX		".seg"
#define JSON_KEY_BLOCK	"blocks"

#define BUFFER_SIZE		(1024*1024*64)
namespace fs {

class StreamComparisor: public Comparisor {
private:

protected:
	Json::Value root;

	std::ostream *stream_output;
	std::istream *stream_left;
	std::istream *stream_right;
	//std::streambuf *cursor_left;
	//std::streambuf *cursor_right;

	virtual int read_left(char * buffer, int length);
	virtual int read_right(char * buffer, int length);
	void output_diff_data(int insert_length, const char * diff, Json::Value* segment);

public:
	int buffer_size;

	StreamComparisor():
		stream_left(0),
		stream_right(0),
		//cursor_left(NULL),
		//cursor_right(NULL),
		buffer_size(BUFFER_SIZE){};
	virtual ~StreamComparisor(){};

	void setLeft(std::istream *left);
	void setRight(std::istream *right);
	void setOutput(std::ostream *output);
	Json::Value compare();
};

}
#endif /* FILECOMPARISOR_H_ */
